module VectorOperations
	implicit none


contains

    !> \brief Cross Product of 2 vectors
    !!
    !! \param v1 - double precision 3-d vector
    !! \param v2 - double precision 3-d vector
    !! \return v - double precision 3-d vector
    !!
	pure function Cross(v1, v2) result (v)
		implicit none
		real(kind=8), dimension(3), intent(in) :: v1, v2
		real(kind=8), dimension(3) :: v

		v(1) = v1(2)*v2(3) - v2(3)*v1(2)
		v(2) = v1(3)*v2(1) - v1(1)*v2(3)
		v(3) = v1(1)*v2(2) - v1(2)*v2(1)
	end function

    !> \brief Normalizes a vetor to a unit-length one
    !! \param v - double precision free length vector
	!!
	subroutine Normalize(v)
		implicit none
		real(kind=8), dimension(:), intent(inout) :: v

		real(kind=8) :: norm

		norm = norm2(v)
		v = v/norm
	end subroutine


    !> \brief Return the Norm Infinity (Maximun Absulote value of the components) of a vector
    !! \param vector - double precision free length vector
    !! \return v - Positive integer
    !!
	pure function norm_infty(vector) result (v)
		implicit none
		real(kind=8), dimension(:), intent(in) :: vector
		real(kind=8) :: v
		integer :: i
		v= 0.0d0
		forall(i=1:size(vector))
			v = max(abs(vector(i)), v)
		end forall
	end function


end module
